The objective of the EJB 3.x specification is to simplify its development by improving the EJB architecture. This simplification is achieved by providing metadata annotations to replace XML configuration. It also provides default configuration values by making entity and session beans POJOs (Plain Old Java Objects) and by making component and home interfaces redundant. The EJB 2.x entity beans is replaced with EJB 3.x entities. EJB 3.0 also introduced the Java Persistence API (JPA) for object-relational mapping of Java objects.
WildFly 8.x supports EJB 3.2 and the JPA 2.1 specifications from Java EE 7. While EJB 3.2 is supported, the sample application in this chapter does not make use of the new features of EJB 3.2 (such as the new TimerService API and the ability to disable passivation of stateful session beans). The sample application is based on Java EE 6 and EJB 3.1. The configuration of EJB 3.x with Java EE 7 is also discussed, and the sample application can be used or modified to run on a Java EE 7 project. We have used a Hibernate 4.3 persistence provider. Unlike some of the other persistence providers, the Hibernate persistence provider supports automatic generation of relational database tables, including the joining of tables.
In this chapter, we will create an EJB 3.x project and build and deploy this project to WildFly 8.1 using Maven. This chapter has the following sections:
Setting up the environment
Creating a WildFly runtime
Creating a Java EE project
Configuring a data source with MySQL database
Creating entities
Creating a JPA persistence configuration file
Creating a Session Bean Facade
Creating a JSP client
Configuring the
jboss-ejb3-ejb
subprojectConfiguring the
jboss-ejb3-web
subprojectConfiguring the
jboss-ejb3-ear
subprojectDeploying the EAR Module
Running the JSP Client
Configuring a Java EE 7 Maven Project